package controller;

import java.io.IOException;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.SystemPropertyUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import entity.Comment;
import entity.Reply;
import entity.Users;
import service.ReplyService;
import service.UsersService;

@Controller
@RequestMapping("/reply")
public class ReplyController {

	@Autowired
	ReplyService replyService;
	@Autowired
	UsersService usersService;
	@Autowired
	Users user;
	@Autowired
	Reply reply;
	@Autowired
	Comment comm;
	
	//添加一条留言
	@RequestMapping("/add")
	public void add(int commId, String detail, HttpServletRequest request, HttpServletResponse response) {
		String username = (String) request.getSession().getAttribute("username");
		System.out.println(commId + detail);
	//	String username = "123";
		user = usersService.findByUserName(username);
		comm.setId(commId);
		reply.setUser(user);
		reply.setComm(comm);
		reply.setDetail(detail);
		reply.setReplyTime(new Date());
		
		try {
			replyService.add(reply);
			response.getWriter().write("success");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
